#include "widget.h"
#include<QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{


    this->setMinimumSize(500,500);
    b1->setText("^_^");
    b1->setParent(this);
    b1->move(50,50);
    b1->show();

    b2 = new QPushButton(this);
    b2->setText("BTN");
    b2->move(100,100);
    b2->show();

    b3 = new QPushButton(this);
    b3->setText("打开子窗口");
    b3->move(150,150);
    b3->show();

    mySubW.setWindowTitle("我是子窗口哟!");
//    connect(b1,&QPushButton::pressed,this,&Widget::close);
//    connect(b2,&QPushButton::clicked,this,&Widget::close);
    connect(b1,&QPushButton::pressed,this,&Widget::mySlot1);
    connect(b2,&QPushButton::clicked,this,&Widget::mySlot2);
    connect(b3,&QPushButton::clicked,[this](){
        qDebug()<<"切换子窗口\n";
        mySubW.show();this->hide();
    });


    connect(&mySubW,&MySubWidget::openParentWindow,[this](){
        qDebug()<<"切换主窗口\n";
        show();mySubW.hide();
    });
}

void Widget::mySlot1(){
    b1->setText("v_v");
}
void Widget::mySlot2(){
    b2->setText("ABC123");
}

Widget::~Widget()
{
//    delete b1;
//    b1 = nullptr;
//    delete b2;
//    b2 = nullptr;
//    delete b3;
//    b3 = nullptr;
}

